﻿using FriendStar.Code;
using FriendStar.Domain.Entity.VBaseData;
using FriendStar.Domain.IRepository.VBaseData;
using FriendStar.Repository.VBaseData;
using System.Collections.Generic;
using System.Linq;
using SqlSugarRepository;

namespace FriendStar.Application.VBaseData
{
    public class V_CPK_42_MX_StoCPKListAccoApp
    {
        private IV_CPK_42_MX_StoCPKListAccoRepository service = new V_CPK_42_MX_StoCPKListAccoRepository();

        public List<V_CPK_42_MX_StoCPKListAccoEntity> GetList(string typeNO)
        {
            return service.FindList(p=>p.FDocuTypeNO==typeNO).OrderBy(t => t.FDocuNO).ToList();
        }
        public List<V_CPK_42_MX_StoCPKListAccoEntity> GetInStockList(Pagination pagination, string companyno, string productionno, string fcurdate, string fcredence, string faccountDate, string FDocuTypeNO)
        {
            var expression = ExtLinq.True<V_CPK_42_MX_StoCPKListAccoEntity>();
            if (!string.IsNullOrEmpty(companyno))
            {          
                expression = expression.And(t => t.FProCompanyNO.Contains(companyno));
            }
            if (!string.IsNullOrEmpty(productionno))
            {
                expression = expression.And(t => t.FProductionNO.Contains(productionno));
            }
            if (!string.IsNullOrEmpty(fcurdate))
            {
                expression = expression.And(t => t.FCurDate.Contains(fcurdate));
            }
            if (!string.IsNullOrEmpty(fcredence))
            {
                expression = expression.And(t => t.FCredence.Contains(fcredence));
            }
            if (!string.IsNullOrEmpty(faccountDate))
            {
                expression = expression.And(t => t.FAccountDate.Contains(faccountDate));
            }
            if(!string.IsNullOrEmpty(FDocuTypeNO))
            {
                expression = expression.And(t => t.FDocuTypeNO == (FDocuTypeNO));
            }
            else
            {
                expression = expression.And(t => t.FDocuTypeNO =="CR"|| t.FDocuTypeNO=="CW");
            }
            return service.FindList(expression,pagination).OrderBy(t => t.UseUnit).ToList();
        }

        public List<V_CPK_42_MX_StoCPKListAccoEntity> GetInStockInfo( string fdocuno)
        {
            var expression = ExtLinq.True<V_CPK_42_MX_StoCPKListAccoEntity>();
            expression = expression.And(t => t.FDocuNO == (fdocuno + ""));
            return service.FindList(expression).OrderBy(t => t.UseUnit).ToList();
        }

        public List<V_CPK_42_MX_StoCPKListAccoEntity> GetOutStockInfo(string fdocuno)
        {
            var expression = ExtLinq.True<V_CPK_42_MX_StoCPKListAccoEntity>();
            expression = expression.And(t => t.FDocuTypeNO == "CC");
            expression = expression.And(t => t.FDocuNO == (fdocuno + ""));
            return service.FindList(expression).OrderBy(t => t.UseUnit).ToList();
        }
        public List<V_CPK_42_MX_StoCPKListAccoEntity> GetOutParameterGridJson(Pagination pagination, string companyname, string productionno, string fcurdate, string fvoucherno, string ledgerdate)
        {
            var expression = ExtLinq.True<V_CPK_42_MX_StoCPKListAccoEntity>();
            if (!string.IsNullOrEmpty(companyname))
            {          
                expression = expression.And(t => t.FProCompanyName.Contains(companyname));
            }
            if (!string.IsNullOrEmpty(productionno))
            {
                expression = expression.And(t => t.FProductionNO.Contains(productionno));
            }
            if (!string.IsNullOrEmpty(fcurdate))
            {
                expression = expression.And(t => t.FCurDate.Contains(fcurdate));
            }
            if (!string.IsNullOrEmpty(fvoucherno))
            {
                expression = expression.And(t => t.FCredence.Contains(fvoucherno));
            }
            if (!string.IsNullOrEmpty(ledgerdate))
            {
                expression = expression.And(t => t.FAccountDate.Contains(ledgerdate));
            }               
            expression = expression.And(t => t.FDocuTypeNO==("CC"));

            return service.FindList(expression, pagination).OrderByDescending(t => t.FDocuNO).ToList();
        }
        
    }
}